package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.sys.MessageGroup;
import com.prs.crm.service.sys.MessageGroupService;

public class MessageGroupAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private MessageGroup messageGroup;
	private MessageGroupService messageGroupService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public MessageGroup getMessageGroup() {
		return messageGroup;
	}
	public void setMessageGroup(MessageGroup messageGroup) {
		this.messageGroup = messageGroup;
	}
	public MessageGroupService getMessageGroupService() {
		return messageGroupService;
	}
	public void setMessageGroupService(MessageGroupService messageGroupService) {
		this.messageGroupService = messageGroupService;
	}
	@Action("listMessageGroup")
	public String listMessageGroup(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(MessageGroup.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMessageGroupService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editMessageGroup")
	public String editMessageGroup(){
		if(ids!=null){
			this.messageGroup=this.getMessageGroupService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveMessageGroup",results={
			@Result(name="success",type="redirect",location="listMessageGroup"),
			@Result(name="error",type="chain",location="editMessageGroup")
	})
	public String saveMessageGroup(){
		this.getMessageGroupService().save(messageGroup);
		return SUCCESS;
	}
	
	@Action(value="removeMessageGroup",results={
			@Result(name="success",type="redirect",location="listMessageGroup"),
			@Result(name="error",type="chain",location="listMessageGroup")
	})
	public String removeMessageGroup(){
		if(ids!=null){
			this.messageGroup=this.getMessageGroupService().get(ids[0]);
		}
		this.getMessageGroupService().batchRemove(ids);
		return SUCCESS;
	}
}
